package test2.baidu.lbs;

import java.io.IOException;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;

public class App {
	
	static String url = "http://api.map.baidu.com/geocoder/v2/";
	static String apikey = "0Dfe3c414325b59b9440109b6a1cd546";
	
	/**
	 *  http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding
	 *  http://lbsyun.baidu.com/apiconsole/key?application=key
	 * @param args
	 */

	static String address = "北京市海淀区中关村大街49号(人大东门人大附中间)";
	static String city = "北京";
	
	public static void main(String[] args) {
		try {
			OkHttpClient client = new OkHttpClient();
			Request request = new Request.Builder()
					.url(url + "?output=json&ak=" + apikey + "&address=" + address + "&city=" + city)
					.build();
			Response response = client.newCall(request).execute();
			String html = response.body().string();
			JSONObject json = JSON.parseObject(html);
			System.out.println(json);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
